#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int Slow(int n) {
        int sum = 0;
        while (n) {
            sum += (n % 10) * (n % 10);
            n /= 10;
        }
        return sum;
    }
    int Fast(int n) {
        int num = Slow(n);
        num = Slow(num);
        return num;
    }
    bool isHappy(int n) {
        int slow = Slow(n);
        int fast = Fast(n);
        while (slow != fast) {
            slow = Slow(slow);
            fast = Fast(fast);
        }
        if (slow == 1) {
            return true;
        }
        else {
            return false;
        }
    }
};
int main()
{
    int n = 2;
    Solution s1;
    bool b = s1.isHappy(n);
    cout << b << ' ';
    cin >> n;
	return 0;
}